<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>小力健康</title>
    <meta name="description" content="小力健康">
    <meta name="keywords" content="小力健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="shortcut icon" href="../img/favicon.ico">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript" src="../plugins/element-ui/lib/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/axios-0.18.0.js"></script>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>订单管理<small>支付记录</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>支付记录</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="订单号/交易号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="search()" class="dalfBut">查询</el-button>
<!--                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>-->
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" border stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="orderNo" label="订单号" align="center"></el-table-column>
                <el-table-column prop="payTime" label="支付时间" align="center"></el-table-column>
                <el-table-column prop="transactionId" label="交易流水号" align="center"></el-table-column>
                <el-table-column prop="totalFee" label="费用" align="center"></el-table-column>
                <el-table-column prop="tradeState" label="交易状态" align="center"></el-table-column>
                <el-table-column label="支付方式" align="center" width="130">
                    <template slot-scope="scope">
                        <span>{{ scope.row.payType == 0 ? '其它支付方式' : scope.row.payType == 1 ? '微信支付' : '支付宝支付'}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-sizes="[10, 20, 30, 40, 50]"
                        :page-size="pagination.pageSize"
                        layout="total,sizes, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增订单" :visible.sync="dialogFormVisible" v-if="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="用户名称" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号" prop="telephone">
                                                <el-input v-model="formData.telephone"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="身份证号码" prop="idCard">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="出生日期">
                                                <el-date-picker v-model="formData.birthday" type="date"
                                                                :picker-options="pickerOptions"
                                                                value-format="yyyy-MM-dd"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="体检日期" prop="orderDate">
                                                <el-date-picker v-model="formData.orderDate" type="date"
                                                                value-format="yyyy-MM-dd"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="预约地址">
                                                <el-select v-model="formData.companyAddress" placeholder="请选择预约地点"
                                                           prop="address">
                                                    <el-option
                                                            v-for="address in selectList"
                                                            :key="address.id"
                                                            :label="address.companyAddress"
                                                            :value="address.companyAddress">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th style="width:30px">选择</th>
                                            <th>套餐名称</th>
                                            <th style="width:80px">适用人群</th>
                                            <th>套餐介绍</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="setmealId" type="checkbox" :value="c.id"
                                                       @change="authTypeChange(c.id)">
                                            </td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.attention}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑支付记录" :visible.sync="dialogFormVisible4Edit" v-if="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="订单号" prop="orderNo">
                                                <el-input v-model="formData.orderNo" disabled="disabled"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="支付时间" prop="payTime" disabled="disabled">
                                                <el-input v-model="formData.payTime" />
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="费用" prop="totalFee">
                                                <el-input v-model="formData.totalFee" />
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="交易流水号" prop="transactionId">
                                                <el-input v-model="formData.transactionId"  disabled="disabled"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="交易状态" prop="tradeState">
                                                <el-input v-model="formData.tradeState" disabled="disabled"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
<!--                            <el-tab-pane label="套餐信息" name="second">-->
<!--                                <div class="checkScrol">-->
<!--                                    <table class="datatable">-->
<!--                                        <thead>-->
<!--                                        <tr>-->
<!--                                            <th style="width:30px">选择</th>-->
<!--                                            <th>套餐名称</th>-->
<!--                                            <th style="width:80px">适用人群</th>-->
<!--                                            <th>套餐介绍</th>-->
<!--                                        </tr>-->
<!--                                        </thead>-->
<!--                                        <tbody>-->
<!--                                        <tr v-for="c in tableData">-->
<!--                                            <td>-->
<!--                                                <input :id="c.id" v-model="setmealId" type="checkbox" :value="c.id"-->
<!--                                                       @change="authTypeChange(c.id)">-->
<!--                                            </td>-->
<!--                                            <td><label :for="c.id">{{c.name}}</label></td>-->
<!--                                            <td><label :for="c.id">{{c.attention}}</label></td>-->
<!--                                            <td><label :for="c.id">{{c.remark}}</label></td>-->
<!--                                        </tr>-->
<!--                                        </tbody>-->
<!--                                    </table>-->
<!--                                </div>-->
<!--                            </el-tab-pane>-->
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            pickerOptions: {
                disabledDate(time) {
                    // return time.getTime() > Date.now() - 8.64e7;
                    return time.getTime() > Date.now();
                }
            },
            dataList: [],//当前页要展示的分页列表数据
            selectList: [],//预约地址数据
            formData: {},//表单数据
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            doctors: [],//健康管理师集合
            activeName: "first",
            setmealId: [],
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            rules: {//校验规则
                name: [{required: true, message: '用户名称为必填项', trigger: 'blur'}],
                telephone: [{required: true, message: '手机号为必填项', trigger: 'blur'},
                    {pattern: /^[1][3,4,5,7,8][0-9]{9}$/, message: '手机号格式错误', trigger: 'blur'}
                ],
                idCard: [{required: true, message: '身份证号码为必填项', trigger: 'blur'},
                    {
                        pattern: /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i,
                        message: '身份证格式错误了,请填写正确的格式',
                        trigger: 'blur'
                    }
                ],
                orderDate: [{required: true, message: '体检日期为必填项', trigger: 'blur'}],
                address: [{required: true, message: '预约地址为必填项', trigger: 'blur'}],
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //VUE日期转换
            dateFormat: function (time) {
                var date = new Date(time);
                var year = date.getFullYear();
                /* 在日期格式中，月份是从0开始的，因此要加0
                 * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
                 * */
                var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                // 拼接
                return year + "-" + month + "-" + day;
            },
            //实现checkbox复选框单选功能
            authTypeChange(params) {
                let index = this.setmealId.indexOf(params)
                if (index >= 0) {
                    this.setmealId = [params]
                } else {
                    this.setmealId.splice(index, 1)
                }
            },
            //没有操作权限弹出框
            showMessage(r) {
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            },
            //编辑
            handleEdit() {
                this.formData.setmealId = this.setmealId[0];

                axios.post("/payLog/edit", this.formData).then((res) => {
                    //关闭编辑窗口
                    this.dialogFormVisible4Edit = false;
                    if (res.data.flag) {
                        //操作成功
                        this.$message.success(res.data.message);
                    } else {
                        //操作失败
                        this.$message.error(res.data.message);
                    }
                }).catch((res) => {
                    this.showMessage(res);
                }).finally(() => {
                    //重新进行分页查询
                    this.findPage();
                });
            },
            //添加
            handleAdd() {
                //校验
                this.$refs['dataAddForm'].validate((valid) => {
                    if (valid) {
                        this.activeName = "first";
                        if (this.setmealId[0] != undefined) {
                            this.formData.setmealId = this.setmealId[0] + "";
                            axios.post("/orderlist/add", this.formData).then((res) => {
                                if (res.data.flag) {
                                    this.tableData = res.data.data;
                                    this.$message.success(res.data.message);
                                } else {
                                    this.$message.error(res.data.message);
                                }
                            }).catch((res) => {
                                this.showMessage(res);
                            }).finally(() => {
                                this.dialogFormVisible = false;
                                this.findPage();
                            });
                        } else { // 失败
                            this.$message.error("请选择一个要预约的套餐!");
                            return false;
                        }
                    } else { // 失败
                        this.$message.error("数据校验失败，请检查你的输入信息是否正确!");
                        return false;
                    }
                });

            },
            search() {
                this.pagination.currentPage = 1;
                this.findPage();
            },
            //分页查询
            findPage() {
                axios.post("/payLog/findPage", {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                }).then((res) => {
                    this.pagination.total = res.data.total;
                    /*循环更改日期格式*/
                    // for (i in res.data.rows) {
                    //     res.data.rows[i].payTime = this.dateFormat(res.data.rows[i].payTime);
                    // }
                    this.dataList = res.data.rows;
                }).catch((res) => {
                    this.showMessage(res);
                });
            },
            // 重置表单
            resetForm(formName) {
                this.setmealId = [];
                this.formData = {};
                this.activeName = "first";
                if (this.$refs[formName] !== undefined) {
                    this.$refs[formName].resetFields()
                }
            },
            // 弹出添加窗口
            handleCreate() {
                this.dialogFormVisible = true;
                this.resetForm("dataAddForm");

                //查询套餐
                axios.post("/setmeal/findAll").then((res) => {
                    if (res.data.flag) {
                        this.tableData = res.data.data;
                    } else {
                        this.$message.error(res.data.message);
                    }
                }).catch((res) => {
                    this.showMessage(res);
                });

                //查询公司地址
                axios.post("/map/getAddressDetail").then((res) => {
                    if (res.data.flag) {
                        this.selectList = res.data.data;
                    } else {
                        this.$message.error(res.data.message);
                    }
                }).catch((res) => {
                    this.showMessage(res);
                });
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.dialogFormVisible4Edit = true;
                this.resetForm("dataEditForm");
                //发送ajax请求，根据检查组ID查询当前检查组数据，用于基本信息的回显
                axios.get("/payLog/findByid?id=" + row.id).then((res) => {
                    if (res.data.flag) {
                        this.formData = res.data.data;
                    } else {
                        this.$message.error(res.data.message);
                    }
                }).catch((res) => {
                    this.showMessage(res);
                });
            },
            // 初始页currentPage、初始每页数据数pagesize和数据data
            handleSizeChange(size) {
                this.pagination.pageSize = size;
                this.findPage();
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                this.$confirm('此操作将永久删除该预约数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {//点击确认 - 执行
                    //用户点击确定按钮，发送ajax请求，将检查项ID提交到Controller进行处理
                    axios.get("/payLog/delete?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            //执行成功
                            //弹出成功提示信息
                            this.$message.success(res.data.message);
                            //重新进行分页查询
                            this.findPage();
                        } else {
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).catch((res) => {
                        this.showMessage(res);
                    });
                }).catch(() => {//点击取消 - 执行
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    });
                });
            }
        }
    })
</script>
</html>